/**
 * 
 */
package com.track.threads;

import com.track.views.MapTileView;

import android.content.Context;
import android.graphics.Canvas;
import android.os.Handler;
import android.view.SurfaceHolder;

/**
 * @author narunas
 *
 */
public class SurfaceViewThread extends Thread{

	public static Boolean mSetToRun = false;
	
	private static Handler mHandler;
	private static SurfaceHolder mHolder;
	private static Context context;
	private static MapTileView mView;
	
	public SurfaceViewThread(Context cntx, SurfaceHolder holder, Handler handler, MapTileView v ) {
		
		context = cntx;
		mHolder = holder;
		mHandler = handler;
		
		mView = v;
		
	}

	@Override
	public void run() {
		
		while (mSetToRun) {
            Canvas c = null;
            try {
                c = mHolder.lockCanvas(null);
                synchronized (mHolder) {
                
                	mView.updateMap(c);
                	
                }
            } finally {
            	
            	
                if (c != null) {
                    
                	mHolder.unlockCanvasAndPost(c);
                
                }
            }
        }
	
	}

	public void runThread(){
		start();
	}
	
	
	
}
